---
category: Navigation
created: '2019-11-17'
description: Create a menu with CSS flexbox
keywords: css flexbox, css menu
thumbnail: /assets/css-layout/thumbnails/menu.png
title: Menu
---

## HTML

```html index.html
<div class="menu">
    <!-- Normal menu item -->
    <div class="menu__item">...</div>

    <!-- With hot key -->
    <div class="menu__item">
        <!-- Label -->
        ...
        <!-- Hot key -->
        <div class="menu__hotkey">...</div>
    </div>

    <!-- With image and hot key -->
    <div class="menu__item">
        <!-- Image -->
        ...

        <!-- Label -->
        ...

        <!-- Hot key -->
        <div class="menu__hotkey">...</div>
    </div>

    <!-- Divider -->
    <div class="menu__divider"></div>
</div>
```

## CSS

```css styles.css
.menu {
    display: flex;
    flex-direction: column;

    /* Border */
    border: 1px solid #d1d5db;
    border-radius: 0.25rem;
}

.menu__item {
    /* Center the content horizontally */
    align-items: center;
    display: flex;
}

.menu__hotkey {
    /* Push the hot key to the right */
    margin-left: auto;
}

.menu__divider {
    border-bottom: 1px solid #d1d5db;
    height: 1px;
}
```

<Playground>
```css placeholders.css hidden
.rectangle {
    background: #d1d5db;
    border-radius: 0.25rem;
    height: var(--rectangle-height);
    width: var(--rectangle-width);
}
.rectangle--hor.rectangle--20 {
    --rectangle-width: 20%;
}
.rectangle--hor.rectangle--40 {
    --rectangle-width: 40%;
}
.rectangle--hor.rectangle--60 {
    --rectangle-width: 60%;
}
.rectangle--hor.rectangle--80 {
    --rectangle-width: 80%;
}
.rectangle--hor.rectangle--100 {
    --rectangle-width: 100%;
}
.rectangle--hor.rectangle--sm {
    --rectangle-height: 0.5rem;
}
.rectangle--hor.rectangle--md {
    --rectangle-height: 2rem;
}
.rectangle--hor.rectangle--lg {
    --rectangle-height: 4rem;
}
.rectangle--ver.rectangle--20 {
    --rectangle-height: 20%;
}
.rectangle--ver.rectangle--40 {
    --rectangle-height: 40%;
}
.rectangle--ver.rectangle--60 {
    --rectangle-height: 60%;
}
.rectangle--ver.rectangle--80 {
    --rectangle-height: 80%;
}
.rectangle--ver.rectangle--100 {
    --rectangle-height: 100%;
}
.rectangle--ver.rectangle--sm {
    --rectangle-width: 0.5rem;
}
.rectangle--ver.rectangle--md {
    --rectangle-width: 2rem;
}
.rectangle--ver.rectangle--lg {
    --rectangle-width: 4rem;
}
```

```css styles.css hidden
body {
    align-items: center;
    display: flex;
    justify-content: center;
}

.menu {
    display: flex;
    flex-direction: column;

    /* Border */
    border: 1px solid #d1d5db;
    border-radius: 0.25rem;

    /* Demo */
    width: 16rem;
}

.menu__item {
    /* Center the content horizontally */
    align-items: center;
    display: flex;

    height: 2rem;
    padding: 0.25rem;
}
.menu__item:hover {
    background: #e5e7eb;
}

.menu__hotkey {
    /* Push the hot key to the right */
    margin-left: auto;
}

.menu__divider {
    border-bottom: 1px solid #d1d5db;
    height: 1px;
}
```

```html index.html hidden
<div class="menu">
    <div class="menu__item">
        <div class="rectangle rectangle--hor rectangle--sm rectangle--80"></div>
    </div>
    <div class="menu__item">
        <div class="rectangle rectangle--hor rectangle--sm rectangle--60"></div>
        <div class="menu__hotkey">⌘ C</div>
    </div>
    <div class="menu__divider"></div>
    <div class="menu__item">
        <div class="rectangle rectangle--hor rectangle--sm rectangle--40"></div>
        <div class="menu__hotkey">⌘ V</div>
    </div>
</div>
```
</Playground>
